<?php

require_once 'func_theme.php';
require_once 'func_panel.php';

option_load();

//Remove unused wp_head for SEO
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );
remove_action('wp_head','rsd_link');
remove_action('wp_head','wlwmanifest_link');
remove_action('wp_head','wp_generator');

//Use customed jQuery Libary, From Google Fast CDN
if (!is_admin()) {
	wp_deregister_script('jquery');
}

//Register Menu
if (function_exists('register_nav_menus')){
	register_nav_menus( array(
'menubar' => '顶部菜单'
) );
}

//Register Sidebar
if ( function_exists('register_sidebar') )
{
	register_sidebar(array(
    	'name' => '左边栏',
		'id' => 'left',
    	'description' => '左侧的边栏，建议设置分类、时间、标签',
        'before_widget' => '<div id="%1$s" class="%2$s">',
        'after_widget' => '</div>',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
	));
	register_sidebar(array(
		'name' => '右边栏',
		'id' => 'right',
		'description' => '主内容右侧的边栏，建议设置文章列表、评论等',
		'before_widget' => '',
        'after_widget' => '',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
	));
	register_sidebar(array(
		'name' => '文章下方',
		'id' => 'bottom',
		'description' => '单个文章下侧的边栏，建议设置相关文章、最新文章、随便看看等',
		'before_widget' => '',
        'after_widget' => '',
        'before_title' => '<span>',
        'after_title' => '</span>',
	));
}

//Add Theme widgets
add_action('widgets_init', create_function('', 'return register_widget("iGooglerWidget");'));
class iGooglerWidget extends WP_Widget {
	/** constructor */
	function iGooglerWidget() {
		parent::WP_Widget(false, $name = 'iGooglerWidget');
	}

	/** @see WP_Widget::widget */
	function widget($args, $instance) {
		extract( $args );
		$title = apply_filters('widget_title', $instance['title']);
		$type = $instance['type'];
		$number = $instance['number'];
		?>
		<?php echo $before_widget; ?>
		<?php if ( $title )
		echo $before_title . $title . $after_title; ?>

		<?php echo '<ul>';?>
		<?php if($type=="random"){
			echo get_random_posts($number);
		} elseif($type=="related"){
			echo wp_get_related_posts($number);
		} elseif($type=="most_comments"){
			echo get_most_comments_posts();
		} elseif($type=="most_views") {
			if (function_exists('get_most_viewed'))
			get_most_viewed('post',$number);
			else
			echo "<li>请安装wp-views插件</li>";
		}
		?>
		<?php echo '</ul>';?>
		<?php echo $after_widget; ?>
		<?php
	}

	/** @see WP_Widget::update */
	function update($new_instance, $old_instance) {
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['type'] = strip_tags($new_instance['type']);
		$instance['number'] = strip_tags($new_instance['number']);
		return $instance;
	}

	/** @see WP_Widget::form */
	function form($instance) {
		$instance = wp_parse_args((array)$instance,array('title'=>'文章列表','type'=>'most_views','number'=>5));
		$title = esc_attr($instance['title']);
		$type = $instance['type'];
		$number = $instance['number'];
		?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
	name="<?php echo $this->get_field_name('title'); ?>" type="text"
	value="<?php echo $title; ?>" /></p>
<p><label for="<?php echo $this->get_field_id('type'); ?>">选择类型：</label>
<select id="<?php echo $this->get_field_id('type'); ?>"
	name="<?php echo $this->get_field_name('type'); ?>" class="widefat">
	<option value="random"
	<?php if($type=='random')echo 'selected="selected"';?>>随机文章</option>
	<option value="related"
	<?php if($type=='related')echo 'selected="selected"';?>>相关文章</option>
	<option value="most_comments"
	<?php if($type=='most_comments')echo 'selected="selected"';?>>最多评论</option>
	<?php if (function_exists('get_most_viewed')){?>
	<option value="most_views"
	<?php if($type=='most_views')echo 'selected="selected"';?>>最多查看</option>
	<?php }?>
</select></p>
<p><label for="<?php echo $this->get_field_id('number'); ?>">文章数目：</label>
<input id="<?php echo $this->get_field_id('number'); ?>"
	name="<?php echo $this->get_field_name('number'); ?>" type="text"
	value="<?php echo $number;?>" size="3" /></p>
	<?php
	}

} // class iGooglerWidget

function jiangge_comments($comment, $args, $depth) {
	$GLOBALS['comment'] = $comment;
	global $commentcount;
	if(!$commentcount) {
		$commentcount = 0;
	}
	?>

<li class="comment" id="comment-<?php comment_ID() ?>">
<div class="author"><?php if (function_exists('get_avatar') && get_option('show_avatars')) { echo get_avatar($comment, 40); } ?>
<div class="name"><?php if (get_comment_author_url()) : ?> <a
	class="url" target="_blank"
	href="<?php comment_author_url() ?>"><?php else : ?><span><?php endif; ?><?php comment_author(); ?><?php if(get_comment_author_url()) : ?></a><?php else : ?></span><?php endif; ?>
</div>
	<?php comment_date('Y-m-j');?> <br />
	<?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
	<?php
	if (function_exists("qc_comment_edit_link")) {
		qc_comment_edit_link('', ' | ', '', '编辑');
	}
	edit_comment_link('高级编辑', ' | ', '');
	?></div>
<div class="info"><?php if ($comment->comment_approved == '0') : ?>
<p><small>您的评论正在等待审核</small></p>
	<?php endif; ?>
<div id="commentbody-<?php comment_ID() ?>"><?php comment_text(); ?></div>
</div>
<div class="clear">&nbsp;</div>
	<?php }?>